<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 
    
	<script type="text/javascript">
		//城市树数据源
		var tree_store = new Ext.data.JsonStore({
    		root: "data",
    		totalProperty: "total",
    		fields: ["id","text","leaf"],
    		url: "tree!city.action"
    	});
		//计费列表数据源
		var data_store = new Ext.data.JsonStore({
			root: "data",
        	totalProperty: "total",
			fields: ["epibolyno", "cityno", "envelop", "reckoning","print", "envcost",
				"envlopweight","totalweight","epibolyname","cityname"],
        	url: "costPar!list.action"
    	});
		
		//定义数据显示面板
		var p1 = {
			id: "p1",
			region: "center",
			xtype: "grid",
			stripeRows:true,
			loadMask : true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
			autoExpandColumn:"epibolyname",//自动填充
			autoExpandMin : 100,//自动填充最小宽度
			store: data_store,
			headersDisabled: true,
			columns:[
    	    	new Ext.grid.RowNumberer({header: "序号", width: 50}),
    	    		{header: "城市",			dataIndex: "cityname",	menuDisabled: true},
   					{header: "外包商名称",	dataIndex: "epibolyname",id:"epibolyname",	menuDisabled: true},
   					{	header: "信封费用",	menuDisabled: true,	
   						dataIndex: "envelop",
   						editor: new Ext.grid.GridEditor(
   							new Ext.form.NumberField({
   								allowBlank:false
   							})
   						)
   					},{	header: "账单印刷费",	menuDisabled: true,
   						dataIndex: "reckoning",
   						editor: new Ext.grid.GridEditor(
   							new Ext.form.NumberField({
   								allowBlank:false
   							})
   						)
   					},{	header: "账单打印费",	menuDisabled: true,
   						dataIndex: "print",
   						editor: new Ext.grid.GridEditor(
   							new Ext.form.NumberField({
   								allowBlank:false
   							})
   						)
   					},{	header: "封装费",		menuDisabled: true,
   						dataIndex: "envcost",
   						editor: new Ext.grid.GridEditor(
   							new Ext.form.NumberField({
   								allowBlank:false
   							})
   						)	
   					},{	header: "信封克重",		menuDisabled: true,
   						dataIndex: "envlopweight",
   						editor: new Ext.grid.GridEditor(
   							new Ext.form.NumberField({
   								allowBlank:false
   							})
   						)
   					},{	header: "总克重",		menuDisabled: true,
   						id: "totalweight",
   						dataIndex: "totalweight",	
   						editor: new Ext.grid.GridEditor(
   							new Ext.form.NumberField({
   								allowBlank:false
   							})
   						)
   					}
			],
			buttonAlign: "center",
			bbar: new Ext.ux.PagingToolbar({
   	        	pageSize: limit,
   	        	store: data_store
   	        }),
			listeners: {
				"validateedit": function(e){
					var para = e.field;
					var da={
							"costPar.epibolyno": e.record.data["epibolyno"],
							"costPar.cityno": e.record.data["cityno"],
							"costPar.envelop": e.record.data["envelop"],
							"costPar.reckoning": e.record.data["reckoning"],
							"costPar.print": e.record.data["print"],
							"costPar.envcost": e.record.data["envcost"],
							"costPar.envlopweight": e.record.data["envlopweight"],
							"costPar.totalweight": e.record.data["totalweight"]
						};
					da["costPar."+para]=e.value;
					Ext.Ajax.request({
						clientValidation: true,
						params: da,
						url: "costPar!upd.action",
						success: function(response, opts){
							var d=eval("("+response.responseText+")");
							if(d.code == "0"){
								e.cancel = true;
								e.record.data[e.field] = e.value;
							} else {
								e.cancel = true;
								e.record.data[e.field] = e.originalValue;
							}
						}
					});
				}
			}
		};

	
	var costpar_pel = new Ext.Panel({
		layout: "border",
		border : false, 
		items: [{
			id: "cityTree",
			xtype: "billTreePanel",
			dataUrl: "tree!city.action",
			autoScroll: true,
			root: new Ext.tree.AsyncTreeNode({
				id: "root",
				expanded : true		// 自动展开节点
			}),
			listeners: {
				"click": function(node){
					tree_store.load({params:{node:node.attributes.id}});
					if(node.isLeaf()) {
						data_store.baseParams = data_store.baseParams || {};
						data_store.baseParams["costPar.cityno"] = node.attributes.id;
						data_store.load({params:{start : 0,limit : limit}});
					}
				}
			}
		},p1]
	});	
	data_store.load();
	
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(costpar_pel);
	CenterPanel.doLayout();
	</script>
    